// page/home/home.js
import {Home} from 'home-model.js';
var home = new Home();

Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this._loadData();
  },

  _loadData:function(){
    let that = this
    var id = 1;
    // home.getBanner(id, this.callBack);
    //获取banner
    
    home.getBanner(id,(res)=>{
        that.setData({
            banner:res.items
        })
    });

    home.getTheme((res)=>{
      that.setData({
        theme: res
      })
    })

    //获取商品列表
    home.getProducts((res)=>{
        that.setData({
          productsArr: res
        })
    })



  },


  //点击banner去到具体的商品
  onProductsItemTap:function(e){
    var that = this;
    var id = that.getEvenData(e,'id');
    wx.navigateTo({
      url: '../product/index?id='+id
    })
  },


  //点击主题跳转
  onThemeItemTap: function (e) {
    var that = this;
    var id = that.getEvenData(e, 'id');
    var name = that.getEvenData(e, 'name');
    wx.navigateTo({
      url: '../theme/index?id=' + id+'&name='+name
    })
  },


  //上传图片
  choose:function(callBack){
    home.chooseImg(this.callBack);
  },
  
  //回调函数
  callBack:function(res) {
     console.log('获取数据',res);
  },




  /*获取e里的参数 */
  getEvenData:function(e,key){
    return e.currentTarget.dataset[key]; 
  }



 
})